import re

def check_legal_citation(article_sections, extract_sections):
    chinese_digit = { '〇', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十' }
    # 定义引用规范的正则表达式
    errors = []
    paragraph_index = 0
    # full_citation_pattern = re.compile(r'中华人民共和国.*?法')
    full_citation_pattern = re.compile(r'(根据|依照|依据)[^；：，。\n]*?第[^条]*?条')
    # short_citation_pattern = re.compile(r'民事诉讼法')
    # doc_citation_pattern = re.compile(r'《[\u4e00-\u9fa5]+》\([^\)]+\)')
    # foreign_citation_pattern = re.compile(r'[a-zA-Z\s]+')
    # a = ['刘正超辩称，1、依照《最高人民法院关于审理民间借贷案件适用法律若干问题的规定》第九条和第十条的规定，编号','刘正超与林荣公司签订的《保证合同》因系从合同而无效。根据《最高人民法院关于审理民间借贷案件适用法律若干问题的规定》第一条：“本规定所称的','际收到任何款项。二、根据《保证合同》（合同编号：ＬＲＢＺ20150023）第一条关于被保']
    for text in article_sections:
        paragraph_index = paragraph_index + 1
        # 检查引用的全称是否正确
        full_citations = full_citation_pattern.finditer(text)
        if full_citations:
            for citation in full_citations:
                match = citation.group()
                suffix_text = ''
                start_pos = -1
                end_pos = -1
                if match is not None and match.startswith('根据'):
                    start_pos = match.find('根据') + len('根据')
                    end_pos = match.find('第')
                    suffix_pos = match.find('条')
                elif match is not None and match.startswith('依照'):
                    start_pos = match.find('依照') + len('依照')
                    end_pos = match.find('第')
                    suffix_pos = match.find('条')
                else:
                    start_pos = match.find('依据') + len('依据')
                    end_pos = match.find('第')
                    suffix_pos = match.find('条')
                if start_pos != -1 and end_pos != -1 and start_pos < end_pos:
                    text = match[start_pos:end_pos].strip()
                    suffix_text = match[end_pos+1:suffix_pos].strip()
                if (text.startswith('《') and (text.endswith(')') or text.endswith('）') or text.endswith('》'))) and (suffix_text[0] in chinese_digit and suffix_text[-1] in chinese_digit):
                    continue
                errors.append({
                    "correct": "",
                    "desc": "",
                    "end": citation.end(),
                    "exception": "False",
                    "explain": "",
                    "label": 2,
                    "label_type": 0,
                    "offset": len(citation.group()),
                    "opt": "",
                    "ppl": "",
                    "pre_insert": "",
                    "source": "",
                    "start": citation.start(),
                    "tag": "",
                    "text": "",
                    "type": f"{citation.group()}，引用法律、法规、司法解释格式错误",
                    "url": "",
                    "word": "",
                    # "paragraph_index": paragraph_index
                })

        # 检查引用的简称是否正确
        # short_citations = short_citation_pattern.findall(text)
        # if short_citations:
        #     print("找到以下法律简称引用：")
        #     for citation in short_citations:
        #         print(citation)
        # else:
        #     print("未找到法律简称引用。")

        # 检查引用公文格式是否正确
        # doc_citations = doc_citation_pattern.findall(text)
        # if doc_citations:
        #     print("找到以下公文引用：")
        #     for citation in doc_citations:
        #         print(citation)
        # else:
        #     print("未找到公文引用。")

        # 检查引用外文是否注明中文译文
        # foreign_citations = foreign_citation_pattern.findall(text)
        # if foreign_citations:
        #     print("找到以下外文引用：")
        #     for citation in foreign_citations:
        #         print(citation)
        # else:
        #     print("未找到外文引用。")

    return errors

# 示例文本
# text = """
# 根据《中华人民共和国民事诉讼法》（以下简称民事诉讼法）的规定，...
# 请参阅《最高人民法院关于适用<中华人民共和国民事诉讼法>的解释》（法释〔2015〕5号），...
# 参考 Smith's theory (史密斯理论)。
# """
#
# # 调用函数检查文本
# check_legal_citation(text)
